import pymysql

try:
    # 连接时直接指定目标数据库（如：test_db）
    db = pymysql.connect(
        host="localhost",
        user="root",
        password="677787",
        database="aa"  # 要查看的数据库名
    )

    cursor = db.cursor()

    # 查看当前数据库的所有表
    cursor.execute("SHOW TABLES;")
    tables = cursor.fetchall()
    print(f"数据库test_db中的表:")
    for table in tables:
        print(table[0])

except Exception as e:
    print("错误：", e)

finally:
    if 'cursor' in locals():
        cursor.close()
    if 'db' in locals():
        db.close()